package pool.process;

import java.util.Hashtable;

import pool.bean.Bean;
import pool.tablename.SubPool;
import smsBean.SubSmsBean;
import utility.CapitalChar;
import utility.ConvertToLower;

/**
 * @author abc
 * Add class which implements Process interface.
 * */
public class Add implements Process 
{	
	
	/**
	 * setObject() method takes parameter like:
	 * @param subObject which is SubPool's object and intake make a call to getInsert() method of respective class in pool package.  
	 */
	public Hashtable<Object, Object> setObject(SubPool subObject) 
	{
		Hashtable<Object,Object> tempHash = new Hashtable<Object,Object>();
		//tempHash.putAll(subObject.initialize());
		//tempHash.putAll(subObject.setPreprocess());
		tempHash.putAll(ConvertToLower.convertHashKey(tempHash));
		if(tempHash.containsKey("errorinput")!=true)
		{
			StringBuffer strBuf = new StringBuffer();
			tempHash.clear();
			strBuf.append("$noresponse$");
			strBuf.append(subObject.getInsert());
			tempHash.put("Result", strBuf.toString());
		}
		return tempHash;		
	}

	


	@SuppressWarnings("unchecked")
	public Hashtable<Object, Object> setSmsObject(SubSmsBean subObject,String request) 
	{
		Hashtable<Object,Object> tempHash = new Hashtable<Object,Object>();
		 StringBuffer strBuf = new StringBuffer();
		 
		tempHash.putAll(subObject.initializeToAdd());
		//tempHash.putAll(subObject.setPreprocess());
		tempHash.putAll(ConvertToLower.convertHashKey(tempHash));
		if(tempHash.containsKey("errorinput")!=true)
		{
			//subObject.processBean();
			try
			{
				Class C = Class.forName("pool.bean."+CapitalChar.makeFirstCharCapital(request)+"_Bean") ;
				Bean beanObject=(Bean)C.newInstance();
				
				beanObject.setDBManager(subObject.getDBManager());
				beanObject.setReqParam(subObject.getReqParam());
				beanObject.setProcess(subObject.getProcess());
				beanObject.setId(subObject.getId());
				
				beanObject.setHashtable(subObject.getHashtable());
				beanObject.setPropertyVector(subObject.getPropertyVector());
				
				//set for transaction class
				beanObject.setTransDetailsVector(subObject.getTransDetailsVector());
				
				
				strBuf.append(beanObject.insert());	
				tempHash.clear();
				tempHash.put("Result", strBuf.toString());
			}
			catch (Exception e) 
			{
				e.printStackTrace();
				// TODO: handle exception
			}				
		}
		return tempHash;		
	}
}